package br.ufrj.dcc.ad.generators;

import java.util.Calendar;
import java.util.Random;

public class ExponentialTimeGenerator extends TimeGenerator{
	/** lambda */
	private double taxa;
	private Random random;
	
	public ExponentialTimeGenerator(double taxa){
		this.taxa = taxa;
		random = new Random(Calendar.getInstance().getTimeInMillis());
	}
	
	public ExponentialTimeGenerator(double periodo,double taxa,double media,double desvioPadrao){
		this.taxa = taxa;
		random = new Random(Calendar.getInstance().getTimeInMillis());
	}
	
	public double getTaxa() {
		return taxa;
	}
	public void setTaxa(double taxa) {
		this.taxa = taxa;
	}

	@Override
	public double geraAmostra() {
		return exponencializa(random.nextDouble());
	}
	
	@Override
	public double geraAmostra(double tempoAtual) {
		return tempoAtual + exponencializa(random.nextDouble());
	}
	
	private double exponencializa(double valor){
		return Math.log(valor)/(-taxa); 
	}

	@Override
	public void resetSeed() {
		//random = new Random(Calendar.getInstance().getTimeInMillis());
		random = new Random(random.nextLong());
	}
}
